<template>
  <view>
    <view class="video_play">
      <!-- 背景 -->
      <image :src="item.img" />
      <!-- 工具栏 -->
      <view class="video_tool">
        <view
          class="iconfont"
          :class="['iconfont',isMute?'iconjingyin':'iconshengyin']"
          @click="handleClick"
        ></view>
        <view class="iconfont iconzhuanfa">
          <button open-type="share" class="mute_btn"></button>
        </view>
      </view>

      <!-- 视频 -->
      <view class="video_wrap">
        <video :src="item.video" objectFit="fill" :muted="isMute" />
      </view>

      <!-- 按钮 -->
      <view class="video_btn">
        <view class="down_btn" @click="handleDownload">下载高清</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      item: {},
      isMute: false
    };
  },
  onLoad() {
    console.log(getApp().globalData);
    this.item = getApp().globalData.item;
  },
  methods: {
    handleClick() {
      this.isMute = !this.isMute;
    },
    async handleDownload(){
      await uni.showLoading({title:"下载中"});

      const { tempFilePath } = 
      (await uni.downloadFile({ url: this.item.video }))[1];

      await uni.saveVideoToPhotosAlbum({
        filePath: tempFilePath
      })

      uni.hideLoading();

      await uni.showToast({title:"下载成功!"});
    }
  }
};
</script>

<style lang="scss" scoped>
.video_play {
  padding: 10rpx;
  image {
    position: absolute;
    height: 100vh;
    width: 100vw;
    z-index: -1;
    filter: blur(10px);
  }
  .video_tool {
    padding: 10rpx;
    height: 80rpx;
    display: flex;
    justify-content: flex-end;
    .iconfont {
      padding: 10rpx;
      border-radius: 50%;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-content: center;
      color: aqua;
      background-color: rgba(0, 0, 0, 0.2);
    }
    .iconjingyin {
      color: red;
    }
    .iconzhuanfa{
      position: relative;
      button {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
      }
    }
  }

  .video_wrap {
    display: flex;
    justify-content: center;
    video {
      width: 360rpx;
      height: 600rpx;
      border: 1rpx solid aqua;
    }
  }
  .video_btn {
    padding: 20rpx;
    display: flex;
    justify-content: center;
    .down_btn {
      width: 360rpx;
      height: 80rpx;
      font-size: 80%;
      border-radius: 50%;
      display: flex;
      color: aqua;
      justify-content: center;
      align-items: center;
      background-color: rgba(0, 0, 0, 0.2);
      border: 3rpx solid aqua;
    }
  }
}
</style>